package com.breeze.components.web.config;

import com.breeze.components.core.xss.JsonHtmlXssTrimSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import java.util.TimeZone;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * jackson配置
 *
 * @author breeze
 */
@AutoConfiguration
public class JacksonConfig implements Jackson2ObjectMapperBuilderCustomizer {

  @Override
  public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
    // 防XSS脚本注入
    jacksonObjectMapperBuilder.deserializers(new JsonHtmlXssTrimSerializer());
    // 默认时区配置
    jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
    // Long序列化为字符串，防止前端溢出
    jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
  }
}
